package cn.ysym.dao;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import cn.ysym.model.OfflineShipping;

public class OfflineShippingDao extends DaoBase {

    public OfflineShippingDao(Context context) {
        super(context);
    }

    public List<OfflineShipping> getUnUp(int sumId) {
        List<OfflineShipping> ret = new ArrayList<>();
        String sql = "select id, sumId, dealerId, orderId, productId, promotionId, code, upSucc, virtualBig, scanTime, shippingId from offline_shipping where upSucc != '1'";
        if (sumId > 0) sql += " and sumId = " + sumId;
        List<String[]> objs = this.query(Integer.MAX_VALUE, sql);
        for (String[] row : objs) {
            OfflineShipping model = new OfflineShipping();
            model.setId(Integer.parseInt(row[0]));
            model.setSumId(Integer.parseInt(row[1]));
            model.setDealerId(row[2]);
            model.setOrderId(row[3]);
            model.setProductId(row[4]);
            model.setPromotionId(row[5]);
            model.setCode(row[6]);
            model.setUpSucc(row[7]);
            model.setVirtualBig(row[8]);
            model.setScanTime(row[9]);
            model.setShippingId(row[10]);
            ret.add(model);
        }

        return ret;
    }

    public boolean isExist(String code) {
        List<String[]> objs = this.query(1, "select id from offline_shipping where code = ?", code);
        if (objs.size() > 0) {
            return true;
        } else return false;
    }

    public void insert(OfflineShipping model) {
        this.execSql("insert into offline_shipping(sumId, dealerId, orderId, productId, promotionId, code, virtualBig, upSucc, scanTime, shippingId) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", model.getSumId(), model.getDealerId(), model.getOrderId(), model.getProductId(), model.getPromotionId(), model.getCode(), model.getVirtualBig(), model.getUpSucc(), model.getScanTime(), model.getShippingId());
    }

    public void update(OfflineShipping model) {
        this.execSql("update offline_shipping set upSucc = ? where id = ?", model.getUpSucc(), model.getId());
    }

}
